package org.example.utils.ipAddressSearchUtil.requestUtil;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

public class RestTemplateGetCountry {

//    private static String utilUrl = "http://61.147.124.120/WebServices/IpAddressSearchWebService.asmx/getCountryCityByIp";
    private static String utilUrl = "http://ws.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx/getCountryCityByIp";

    public static String getCountryByIpAddress(String ipAddress){
        RestTemplate restTemplate = new RestTemplate();
//        System.out.println(utilUrl + "?theIpAddress=" + ipAddress);
        String res = restTemplate.getForObject(
                utilUrl + "?theIpAddress=" + ipAddress
                , String.class);
        String[] split = res.split(">");
        String[] split1 = split[5].split("<");
        String trim = split1[0].trim();
//        System.out.println(trim);
        return trim;
    }

}
